package com.zqh.forum.controller;


import com.zqh.forum.common.AppResult;
import com.zqh.forum.exception.ApplicationException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.NonNull;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/test")
@RestController
@Tag(name ="测试类相关的接口")
//@Tag(name = "测试类的相关接口")
public class TestController {

    @GetMapping("/hello")
    @Operation(summary = "测试接口1：显示spring,hello world")
    public String hello(){
        return "spring ,hello world";
    }

    @Operation(summary = "测试接口4，按传入的姓名显示你好信息")
    @PostMapping("/helloByName")
    @Parameters(@Parameter(name = "username",description = "用户名"))
    public AppResult helloByName (  @RequestParam("name") @NonNull String name) {
        return AppResult.success("hello : " + name);
    }


    @Operation(summary ="测试接口2，显示抛出的异常信息")
    @GetMapping("/exception")
    public AppResult testException () throws Exception {
        throw new Exception("这是一个Exception...");
    }

    @Operation(summary = "测试接口3，显示抛出的自定义的异常信息")
    @GetMapping("/appException")
    public AppResult testApplicationException () {
        throw new ApplicationException("这是一个ApplicationException...");
    }

}
